package com.lb.threadlocal;

import java.util.concurrent.TimeUnit;

/**
 * @author jzhang
 * @version 1.0
 * @date 2022-12-27 11:01
 */
@SuppressWarnings("all")
public class TheadLocalTest {
    static ThreadLocal<Person> tl = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(tl.get());
        }).start();

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            tl.set(new Person());
        }).start();

    }

    static class Person {
        private String name = "zhangsan";
    }
}
